package com.loveprogrammer.eternity.model.effect;

import com.loveprogrammer.eternity.enums.EffectTimeEnum;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.attack.AttackResult;
import com.loveprogrammer.eternity.skill.support.states.BleedState;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @version 1.0.0
 * @description:
 * @author: eric
 * @date: 2023-02-15 17:37
 **/
public class SlicingEffect extends AbstractEffect{
    private int percent;

    public SlicingEffect(String id, int percent) {
        super(id);
        this.percent = percent;
    }

    @Override
    public boolean trigger(EffectTimeEnum effectTimeEnum) {
        return effectTimeEnum.equals(EffectTimeEnum.ATTACK_AFTER);
    }

    @Override
    public StringBuilder doUpdate(Character attack, AttackResult entity,
                            List<? extends Character> attackList, Character[] defence) {
        StringBuilder builder = new StringBuilder();
        if(defence == null){
            return builder;
        }
        // 几率造成出血3秒
        int reduce = (int) (attack.getTechnique() * percent / 100);
        // 流血状态 持续3秒
        for (Character character : defence) {
            BleedState bleedState = new BleedState(character, null, reduce);
            boolean state = character.acquireState(bleedState, 3);
            // 施展成功 启动一个定时器，5秒钟
            if(state){
                setTimeTask(bleedState,3);
                builder.append(character.getName()).append("-- 撕裂触发，附加进入流血状态 持续3秒;");
            }
        }

        return builder;
    }

    public int getPercent() {
        return percent;
    }

    public void setPercent(int percent) {
        this.percent = percent;
    }
}
